package com.itheima.tlias84.controller;

import com.alibaba.fastjson2.JSONObject;
import com.itheima.tlias84.Util.ResultUtil;
import com.itheima.tlias84.config.StudentConfig;
import jakarta.annotation.Resource;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("yml")
public class TestReadYmlController {

//    @Value("${student.name}")
//    String name;
//    @Value("${student.age}")
//    Integer age;
//    @Value("${student.subject}")
//    String[] subject;
//    @Value("${student.teachers}")
//    List<String> list;

    @Resource
    StudentConfig config;
    @Resource
    Environment env;


    @GetMapping
    public ResultUtil readCustomConfigByYml() {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", config.getName());
        jsonObject.put("age", config.getAge());
        jsonObject.put("科目", config.getSubject());
        jsonObject.put("老师", config.getTeachers());
        jsonObject.put("家庭", config.getFamily());
        String[] activeProfiles = env.getActiveProfiles();
        jsonObject.put("active",activeProfiles);
        String property = env.getProperty("server.port");
        jsonObject.put("port",property);


        return ResultUtil.success(jsonObject);

    }
}
